<%--
  Created by IntelliJ IDEA.
  User: Lee
  Date: 2017/11/25
  Time: 10:01
  To change this template use File | Settings | File Templates.
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<div id="msgFromPush"></div>
<script type="text/javascript" src="<c:url value="../assets/js/jquery-2.1.4.js"/>"></script>
<script type="text/javascript">

    if (!!window.EventSource){
        var source = new EventSource("push");
        var s = '';

        source.addEventListener('message',function (e) {
            s+=e.data + "<br/>"
            $("#msgFromPush").html(s);
        });

        source.addEventListener('open',function (e) {
            console.log("连接打开。")
        },false)

        source.addEventListener("error",function (e) {
            if (e.readyState == EventSource.CLOSED){
                console.log("连接失败")
            }else {
                console.log(e.readyState)
            }
        },false)
    }else {
        console.log("不支持")
    }

</script>
</body>
</html>
